package com.moore.controller;

import com.moore.bean.Work;
import com.moore.dto.ResponseData;
import com.moore.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/work")
public class WorkController {
    @Autowired
    WorkService workService;

    @RequestMapping("/getByPID")
    public ResponseData getWorksByPositionId(Integer positionId, String location, String keyword, Integer page, Integer pageSize) {
        List<Work> works = workService.getWorksByPositionId(positionId, location, keyword, page, pageSize);
        return ResponseData.returnList("查询成功", works, workService.getWorkCountByPositionId(positionId, location, keyword));
    }

    @RequestMapping("/getByFilter")
    public ResponseData getWorksByFilter(@RequestBody Map<String, Object> filter) {
        System.out.println(filter);
        List<Work> works = workService.getWorksByFilter(filter);
        return ResponseData.returnList("查询成功", works, workService.getWorkCountByFilter(filter));
    }

    @RequestMapping("/getById")
    public ResponseData getWorkByWID(Integer id) {
            return ResponseData.returnObject("查询成功", workService.getWorkById(id));
    }
}
